<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>快速开始 | Math Complex</title>
    <meta name="description" content="简单易用的JavaScript复数扩展数学库">

    
    <link rel="preload" href="/math-complex/assets/css/0.styles.dc9a62cc.css" as="style"><link rel="preload" href="/math-complex/assets/js/app.a7e80bc5.js" as="script"><link rel="preload" href="/math-complex/assets/js/2.b96ecc85.js" as="script"><link rel="preload" href="/math-complex/assets/js/12.ef27bf30.js" as="script"><link rel="prefetch" href="/math-complex/assets/js/10.e877db03.js"><link rel="prefetch" href="/math-complex/assets/js/11.aa6e74d4.js"><link rel="prefetch" href="/math-complex/assets/js/13.6d5e4273.js"><link rel="prefetch" href="/math-complex/assets/js/3.3a2d5ce2.js"><link rel="prefetch" href="/math-complex/assets/js/4.5f9aa696.js"><link rel="prefetch" href="/math-complex/assets/js/5.8bdadb5e.js"><link rel="prefetch" href="/math-complex/assets/js/6.0954e40b.js"><link rel="prefetch" href="/math-complex/assets/js/7.30d57aa9.js"><link rel="prefetch" href="/math-complex/assets/js/8.6149196e.js"><link rel="prefetch" href="/math-complex/assets/js/9.6ecdb287.js">
    <link rel="stylesheet" href="/math-complex/assets/css/0.styles.dc9a62cc.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/math-complex/" class="home-link router-link-active"><!----> <span class="site-name">Math Complex</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/math-complex/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/math-complex/guide/" class="nav-link router-link-active">
  入门指南
</a></div><div class="nav-item"><a href="/math-complex/API/" class="nav-link">
  API
</a></div><div class="nav-item"><a href="/math-complex/appendix/" class="nav-link">
  附录
</a></div><div class="nav-item"><a href="https://github.com/shawroger/math-complex" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/math-complex/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/math-complex/guide/" class="nav-link router-link-active">
  入门指南
</a></div><div class="nav-item"><a href="/math-complex/API/" class="nav-link">
  API
</a></div><div class="nav-item"><a href="/math-complex/appendix/" class="nav-link">
  附录
</a></div><div class="nav-item"><a href="https://github.com/shawroger/math-complex" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>入门指南</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/math-complex/guide/" class="sidebar-link">简介</a></li><li><a href="/math-complex/guide/start.html" class="active sidebar-link">快速开始</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/math-complex/guide/start.html#使用-npm-安装" class="sidebar-link">使用 npm 安装</a></li><li class="sidebar-sub-header"><a href="/math-complex/guide/start.html#在浏览器中使用" class="sidebar-link">在浏览器中使用</a></li><li class="sidebar-sub-header"><a href="/math-complex/guide/start.html#基本示例" class="sidebar-link">基本示例</a></li></ul></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="快速开始"><a href="#快速开始" class="header-anchor">#</a> 快速开始</h1> <h2 id="使用-npm-安装"><a href="#使用-npm-安装" class="header-anchor">#</a> 使用 npm 安装</h2> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">npm</span> <span class="token function">install</span> math-complex --save
</code></pre></div><h2 id="在浏览器中使用"><a href="#在浏览器中使用" class="header-anchor">#</a> 在浏览器中使用</h2> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token operator">&lt;</span>script src<span class="token operator">=</span><span class="token string">&quot;https://unpkg.com/math-complex@latest&quot;</span><span class="token operator">&gt;</span><span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">&gt;</span>
</code></pre></div><h2 id="基本示例"><a href="#基本示例" class="header-anchor">#</a> 基本示例</h2> <ul><li>使用 <strong>ComplexNumber</strong> 类的方法</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z1 = 3 + 4i</span>
<span class="token keyword">const</span> z2 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z2 = 5 + 12i</span>

<span class="token keyword">const</span> three <span class="token operator">=</span> z1<span class="token punctuation">.</span>real<span class="token punctuation">;</span> <span class="token comment">// Re(z1) = 3</span>
<span class="token keyword">const</span> twelve <span class="token operator">=</span> z2<span class="token punctuation">.</span>imaginary<span class="token punctuation">;</span> <span class="token comment">// Im(z2) = 12</span>

<span class="token keyword">const</span> z3 <span class="token operator">=</span> z1<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z3 = z1 + z2</span>
<span class="token keyword">const</span> z4 <span class="token operator">=</span> z1<span class="token punctuation">.</span><span class="token function">subtract</span><span class="token punctuation">(</span>z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z4 = z1 - z2</span>
<span class="token keyword">const</span> z5 <span class="token operator">=</span> z1<span class="token punctuation">.</span><span class="token function">mult</span><span class="token punctuation">(</span>z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z5 = z1 * z2</span>
<span class="token keyword">const</span> z6 <span class="token operator">=</span> z1<span class="token punctuation">.</span><span class="token function">divide</span><span class="token punctuation">(</span>z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z6 = z1 / z2</span>
</code></pre></div><ul><li>使用 <strong>ComplexReflect</strong> 静态类的函数</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z1 = 3 + 4i</span>
<span class="token keyword">const</span> z2 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z2 = 5 + 12i</span>

<span class="token keyword">const</span> three <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">realize</span><span class="token punctuation">(</span>z1<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Re(z1) = 3</span>
<span class="token keyword">const</span> twelve <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">imagine</span><span class="token punctuation">(</span>z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Im(z2) = 12</span>

<span class="token keyword">const</span> z3 <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>z1<span class="token punctuation">,</span> z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z3 = z1 + z2</span>
<span class="token keyword">const</span> z4 <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">mult</span><span class="token punctuation">(</span>z1<span class="token punctuation">,</span> z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z4 = z1 * z2</span>
<span class="token keyword">const</span> z5 <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">abs</span><span class="token punctuation">(</span>z1<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// |z1| = 5</span>
<span class="token keyword">const</span> z6 <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">contrary</span><span class="token punctuation">(</span>z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// -z2 = 5 - 12i</span>
</code></pre></div><ul><li>使用 <strong>ComplexReflect</strong> 静态类对 <strong>ComplexNumber</strong> 和 JS 原生 <strong>number</strong> 对象混合操作</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> <span class="token punctuation">{</span> 
    abs<span class="token punctuation">,</span>
    add<span class="token punctuation">,</span>
    contrary<span class="token punctuation">,</span>
    mult<span class="token punctuation">,</span>
    imagine<span class="token punctuation">,</span>
    realize
<span class="token punctuation">}</span> <span class="token operator">=</span> ComplexReflect<span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z1 = 3 + 4i</span>
<span class="token keyword">const</span> z2 <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span> <span class="token comment">// z2 = 5</span>

<span class="token keyword">const</span> three <span class="token operator">=</span> <span class="token function">realize</span><span class="token punctuation">(</span>z1<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Re(z1) = 3</span>
<span class="token keyword">const</span> twelve <span class="token operator">=</span> <span class="token function">imagine</span><span class="token punctuation">(</span>z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Im(z2) = 02</span>

<span class="token keyword">const</span> z3 <span class="token operator">=</span> <span class="token function">add</span><span class="token punctuation">(</span>z1<span class="token punctuation">,</span> z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z3 = z1 + z2 = z1 + 5</span>
<span class="token keyword">const</span> z4 <span class="token operator">=</span> <span class="token function">mult</span><span class="token punctuation">(</span>z1<span class="token punctuation">,</span> z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z4 = z1 * z2 = z1 * 5</span>
<span class="token keyword">const</span> z5 <span class="token operator">=</span> <span class="token function">abs</span><span class="token punctuation">(</span>z1<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// |z1| = 5</span>
<span class="token keyword">const</span> z6 <span class="token operator">=</span> <span class="token function">contrary</span><span class="token punctuation">(</span>z2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// -z2 = 5 - 12i</span>
</code></pre></div></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/math-complex/guide/" class="prev router-link-active">
        简介
      </a></span> <!----></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/math-complex/assets/js/app.a7e80bc5.js" defer></script><script src="/math-complex/assets/js/2.b96ecc85.js" defer></script><script src="/math-complex/assets/js/12.ef27bf30.js" defer></script>
  </body>
</html>
